package cs.xwi7xwa.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import cs.xwi7xwa.R;
import cs.xwi7xwa.data.FactDbAdapter;
import cs.xwi7xwa.templates.BumpTemplate;

public class FactView extends BumpTemplate {
    
    public static final String FACT_NUMBER = "factNumber"; 
    
    private int id = -1;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
    	super.onCreate(savedInstanceState);
    	setContentView(R.layout.fact);
    	
    	// Get all extra data that came with the Intent
        Bundle extras = getIntent().getExtras();
    	
    	// Populate the page with the extra data
        if (extras != null)
        {
            // If the id does not exist, then use -1 as default
            id = extras.getInt(FactDbAdapter.KEY_ID, -1);
            String desc = extras.getString(FactDbAdapter.KEY_DESC);
            String exhibitName = extras.getString(ExhibitView.EXHIBIT_NAME);
            int factNumber = extras.getInt(FACT_NUMBER, 0);

            if (id > 0)
            {
                TextView titleView = (TextView) findViewById(R.id.factTitle);
                StringBuilder sb = new StringBuilder();
                if (exhibitName != null)
                {
                    sb.append(exhibitName).append(": ");
                }
                sb.append("Fact #").append(factNumber);
                titleView.setText(sb.toString());
            }
            if (desc != null)
            {
                TextView descView = (TextView) findViewById(R.id.factDesc);
                descView.setText(desc);
            }
        }
        
        // Log this method's execution
        log(null);
    }
    
    public void goToShareView(View view)
    {
        Intent intent = new Intent(view.getContext(), ShareView.class);
        intent.putExtra(FactDbAdapter.KEY_ID, id);
        startActivityForResult(intent, 0);
        
        // Log this method's execution
        log(null);
    }
}
